var prettify = {}

prettify.time = function(t){
    if(typeof t=="string")t = new Date(t.substring(0,19).replace(/-/g,'/'))
    else if(!(t instanceof Date))t = new Date(t)
    var now = new Date()
    var today = new Date(now.toDateString())
    var seconds = (now.getTime() - t.getTime())/1000
    if(seconds<60)return "刚刚";
    if(seconds<3600)return parseInt(seconds/60)+"分钟前"
    var tday = new Date(t.toDateString())
    var days = (today.getTime()-tday.getTime())/86400000
    var time = t.toTimeString().substr(0,5)
    if(days<1)return "今天 "+time
    if(days<2)return "昨天 "+time
    //if(today.getYear()==t.getYear())return (t.getMonth()+1)+"-"+t.getDate()+" "+time
    return t.getFullYear()+"-"+(t.getMonth()+1)+"-"+t.getDate()//+" "+time
}

prettify.money = function(m){
    return parseFloat((m/100).toFixed(2))
}

//溢出隐藏加...
prettify.text = function(str,l){
    if (str.length>l) {
        var str1=str.slice(0,l-4)
        str1+="..."
        return str1
    }else{
        return str
    }
}

//合并两个对象
prettify.extend = function extend(des, src, override){
   if(src instanceof Array){
       for(var i = 0, len = src.length; i < len; i++)
            extend(des, src[i], override);
   }
   for(var i in src){
       if(override || !(i in des)){
           des[i] = src[i];
       }
   }
   return des;
}


module.exports = prettify
